/*!
* 
* Copyright (c) 2009 by yuqiang @ vcedu
* 
* Description:
*		This file contains the audio interface which would be used outside the lib
*
* ChangeLog:
*		$Date$	$Rev$	$Author$
* 
*/	

#include "stdafx.h"

#include "iaudio.h"

#include <rtpipv4address.h>
#include <log4cpp/Category.hh>

#include "audiosession.h"

static log4cpp::Category& Logger = log4cpp::Category::getInstance(__Module__Name+std::string(".iaudio"));

// global variance, we should have only one videSession
static AudioSession __audioSession;
static AudioSessionParams __audioParams;

extern "C"{

	LIBRTP_API void librtp_audio_param_init(struct AudioParam *pParam){
		if(NULL == pParam){
			Logger.error(DEBUG_MSG("pParam is a Null Pointer"));
		}		
		pParam->highPriority = false;
		pParam->portbase = 6000; 
		pParam->acceptOwnPackets = true; 
		pParam->speexMode = WideBand;
		pParam->speexIncomingPT = 96;
		pParam->speexOutgoingPT = 96;

		pParam->inputMultiplier = 3;
		pParam->outputMultiplier = 2;

		pParam->compType = Speex;
	}

	LIBRTP_API bool librtp_audio_init(struct AudioParam *pParam){

		if(NULL == pParam){
			Logger.error(DEBUG_MSG("pParam is a Null Pointer"));
		}

		__audioParams.setUseHighPriority(pParam->highPriority);
		__audioParams.setPortbase(pParam->portbase);
		__audioParams.setAcceptOwnPackets(pParam->acceptOwnPackets);
		__audioParams.setSpeexEncoding(pParam->speexMode);
		__audioParams.setSpeexIncomingPayloadType(pParam->speexIncomingPT);
		__audioParams.setSpeexOutgoingPayloadType(pParam->speexOutgoingPT);
		__audioParams.setInputMultiplier(pParam->inputMultiplier);
		__audioParams.setOutputMultiplier(pParam->outputMultiplier);
		__audioParams.setCompressionType(pParam->compType);

		return __audioSession.init(&__audioParams);
	}

	LIBRTP_API bool librtp_audio_close(){
		return __audioSession.destroy();
	}

	LIBRTP_API bool librtp_audio_addDestination(unsigned char ipAddr[4],unsigned int port){
		return __audioSession.addDestination(RTPIPv4Address(ipAddr,port));
	}

	LIBRTP_API bool librtp_audio_deleteDestination(unsigned char ipAddr[4],unsigned int port){
		return __audioSession.deleteDestination(RTPIPv4Address(ipAddr,port));
	}

	LIBRTP_API bool librtp_audio_clearDestinations(){
		return __audioSession.clearDestinations();
	}

	LIBRTP_API bool librtp_audio_setReceiveMode(ReceiveMode mode){
		return __audioSession.setReceiveMode(static_cast<RTPTransmitter::ReceiveMode>(mode));
	}

	LIBRTP_API bool librtp_audio_addToIgnoreList(unsigned char ipAddr[4],unsigned int port){
		return __audioSession.addToIgnoreList(RTPIPv4Address(ipAddr,port));
	}

	LIBRTP_API bool librtp_audio_deleteFromIgnoreList(unsigned char ipAddr[4],unsigned int port){
		return __audioSession.deleteFromIgnoreList(RTPIPv4Address(ipAddr,port));
	}

	LIBRTP_API bool librtp_audio_clearIgnoreList(){
		return __audioSession.clearIgnoreList();
	}

	LIBRTP_API bool librtp_audio_addToAcceptList(unsigned char ipAddr[4],unsigned int port){
		return __audioSession.addToAcceptList(RTPIPv4Address(ipAddr,port));
	}

	LIBRTP_API bool librtp_audio_deleteFromAcceptList(unsigned char ipAddr[4],unsigned int port){
		return __audioSession.deleteFromAcceptList(RTPIPv4Address(ipAddr,port));
	}

	LIBRTP_API bool librtp_audio_clearAcceptList(){
		return __audioSession.clearAcceptList();
	}

	LIBRTP_API bool librtp_audio_startSendChain(){
		return __audioSession.startSendChain();
	}

	LIBRTP_API bool librtp_audio_stopSendChain(){
		return __audioSession.stopSendChain();
	}

	LIBRTP_API bool librtp_audio_startReceiveChain(){
		return __audioSession.startReceiveChain();
	}

	LIBRTP_API bool librtp_audio_stopReceiveChain(){
		return __audioSession.stopReceiveChain();
	}

	LIBRTP_API bool librtp_audio_startSession(){
		return __audioSession.startSession();
	}

	LIBRTP_API bool librtp_audio_stopSession(){
		return __audioSession.stopSession();
	}

	LIBRTP_API bool librtp_audio_isInit(){
		return __audioSession.isInit();
	}

	LIBRTP_API bool librtp_audio_isSessionRunning(){
		return __audioSession.isSessionRunning();
	}

	LIBRTP_API bool librtp_audio_isSendRunning(){
		return __audioSession.isSendRunning();
	}

	LIBRTP_API bool librtp_audio_isReceiveRunning(){
		return __audioSession.isReceiveRunning();
	}
};
